package com.bamboo.tool.template.torna.view.actions;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.bamboo.tool.config.BambooToolComponent;
import com.bamboo.tool.config.RestfulCloudApplicationCache;
import com.bamboo.tool.entity.NoteData;
import com.bamboo.tool.entity.QueryClassParameter;
import com.bamboo.tool.template.torna.entity.TornaSetting;
import com.bamboo.tool.template.torna.view.dialog.UploadTornaDialogWrapper;
import com.bamboo.tool.util.I18nUtil;
import com.bamboo.tool.util.PsiUtils;
import com.bamboo.tool.view.component.tree.*;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import icons.PluginIcons;
import org.jetbrains.annotations.NotNull;

import javax.swing.tree.TreePath;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class UploadTornaAction extends DumbAwareAction {
    private ApiTree apiTree;

    public UploadTornaAction(ApiTree apiTree) {
        super(I18nUtil.getString("torna.upload"), "", PluginIcons.TORNA_LOGO);
        this.apiTree = apiTree;
    }

    @Override
    public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
        Project project = anActionEvent.getProject();
        QueryClassParameter queryClassParam = PsiUtils.getQueryClassParameter(apiTree);
        TornaSetting state = RestfulCloudApplicationCache.getInstance().getState().getTornaSetting();
        if (StrUtil.isEmpty(state.getToken()) || StrUtil.isEmpty(state.getUserName()) || StrUtil.isEmpty(state.getPassword())) {
            ShowSettingsUtil.getInstance().showSettingsDialog(project, "Torna Setting");
        } else {
            new UploadTornaDialogWrapper(queryClassParam, anActionEvent.getProject()).showAndGet();
        }
    }
}
